package com.kh.pajx.sop.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kh.pajx.sop.base.BaseServiceImpl;
import com.kh.pajx.sop.dao.AreaMangerBackDao;
import com.kh.pajx.sop.domain.AreaMangerBack;
import com.kh.pajx.sop.service.AreaMangerBackService;
@Service
@Transactional
public class AreaMangerBackServiceImpl extends BaseServiceImpl<AreaMangerBack> implements AreaMangerBackService {
	private AreaMangerBackDao areaMangerDao;
    

	
	@Resource
	public void setAreaMangerDao(AreaMangerBackDao areaMangerDao) {
		this.areaMangerDao = areaMangerDao;
	}

	@Override
	public void addAreaManger(AreaMangerBack pwfi) {
		areaMangerDao.save(pwfi);
		
	}

	@Override
	public void updateAreaManger(AreaMangerBack pwfi) {
		areaMangerDao.update(pwfi);
		
	}

	@Override
	public void deleteAreaManger(String uuid) {
		areaMangerDao.delete(uuid);
		
	}

	@Override
	public List<AreaMangerBack> searchAreaManger(Map<String, String> params) {
		StringBuilder sb = new StringBuilder();
		String appState=params.get("appState");
		String appBillCode=params.get("appBillCode");
		String areaCode=params.get("areaCode");
		String IsAppState=params.get("IsAppState");
		try {
			/*if(StringUtils.isNotBlank(appState)&&!"0".equals(appState)&&!"1".equals(appState)){
				throw new Exception("申请状态输入非法");
			    }
			 if(StringUtils.isNotBlank(IsAppState)&&!"0".equals(IsAppState)&&!"1".equals(IsAppState)){
					throw new Exception("申请状态输入非法");
			}
			 if(StringUtils.isNotBlank(appBillCode)&&!PropertyValidate.validateUUID(appBillCode)){
					throw new Exception("申请单号输入不合法");
			}
			 if(StringUtils.isNotBlank(areaCode)&&!PropertyValidate.validateAreaCode(areaCode)){
					throw new Exception("地区编码输入不合法");
			}*/
		
		sb.append("select fb from  AreaMangerBack fb where 1=1 ");
		if (appState != null && !"".equals(appState)) {
			sb.append(" and fb.appState ='").append(appState).append("' ");
		}
		if (appBillCode != null && !"".equals(appBillCode)) {
			sb.append(" and fb.appBillCode ='").append(appBillCode).append("' ");
		}
		if (areaCode != null && !"".equals(areaCode)) {
			sb.append(" and fb.areaCode ='").append(areaCode).append("' ");
		}
		if (IsAppState != null && !"".equals(IsAppState)) {
			sb.append(" and fb.appState !=").append(IsAppState).append(" ").append("and fb.appState !=0");
		}
		sb.append(" order by fb.areaCode,fb.ywEndDate desc ");
		return areaMangerDao.findList(sb.toString());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public AreaMangerBack findAreaMangerById(String id) {
		return areaMangerDao.getById(id);
	}
	@Override
	public List<AreaMangerBack> getAllAreaManger() {
		return areaMangerDao.findAll();
	}

	
}
